home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
os2
/
e33el2.zip
/
emacs
/
19.33
/
lisp
/
lmenu.el
< prev
next >
Wrap
Lisp/Scheme
|
1996-07-02
|
19KB
|
507 lines
;;; lmenu.el --- emulate Lucid's menubar support
;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
;; Keywords: emulations
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Code:
;; First, emulate the Lucid menubar support in GNU Emacs 19.
;; Arrange to use current-menubar to set up part of the menu bar.
(defvar current-menubar)
(setq recompute-lucid-menubar 'recompute-lucid-menubar)
(defun recompute-lucid-menubar ()
(define-key lucid-menubar-map [menu-bar]
(condition-case nil
(make-lucid-menu-keymap "menu-bar" current-menubar)
(error (message "Invalid data in current-menubar moved to lucid-failing-menubar")
(sit-for 1)
(setq lucid-failing-menubar current-menubar
current-menubar nil))))
(setq lucid-menu-bar-dirty-flag nil))
(defvar lucid-menubar-map (make-sparse-keymap))
(or (assq 'current-menubar minor-mode-map-alist)
(setq minor-mode-map-alist
(cons (cons 'current-menubar lucid-menubar-map)
minor-mode-map-alist)))
(defun set-menubar-dirty-flag ()
(force-mode-line-update)
(setq lucid-menu-bar-dirty-flag t))
(defvar add-menu-item-count 0)
;; This is a variable whose value is always nil.
(defvar make-lucid-menu-keymap-disable nil)
;; Return a menu keymap corresponding to a Lucid-style menu list
;; MENU-ITEMS, and with name MENU-NAME.
(defun make-lucid-menu-keymap (menu-name menu-items)
(let ((menu (make-sparse-keymap menu-name)))
;; Process items in reverse order,
;; since the define-key loop reverses them again.
(setq menu-items (reverse menu-items))
(while menu-items
(let ((item (car menu-items))
command name callback)
(cond ((stringp item)
(setq command nil)
(setq name (if (string-match "^-+$" item) "" item)))
((consp item)
(setq command (make-lucid-menu-keymap (car item) (cdr item)))
(setq name (car item)))
((vectorp item)
(setq command (make-symbol (format "menu-function-%d"
add-menu-item-count))
add-menu-item-count (1+ add-menu-item-count)
name (aref item 0)
callback (aref item 1))
(if (symbolp callback)
(fset command callback)
(fset command (list 'lambda () '(interactive) callback)))
(put command 'menu-alias t)
(let ((i 2))
(while (< i (length item))
(cond
((eq (aref item i) ':active)
(put command 'menu-enable
(or (aref item (1+ i))
'make-lucid-menu-keymap-disable))
(setq i (+ 2 i)))
((eq (aref item i) ':suffix)
;; unimplemented
(setq i (+ 2 i)))
((eq (aref item i) ':keys)
;; unimplemented
(setq i (+ 2 i)))
((eq (aref item i) ':style)
;; unimplemented
(setq i (+ 2 i)))
((eq (aref item i) ':selected)
;; unimplemented
(setq i (+ 2 i)))
((and (symbolp (aref item i))
(= ?: (string-to-char (symbol-name (aref item i)))))
(error "Unrecognized menu item keyword: %S"
(aref item i)))
((= i 2)
;; old-style format: active-p &optional suffix
(put command 'menu-enable
(or (aref item i) 'make-lucid-menu-keymap-disable))
;; suffix is unimplemented
(setq i (length item)))
(t
(error "Unexpected menu item value: %S"
(aref item i))))))))
(if (null command)
;; Handle inactive strings specially--allow any number
;; of identical ones.
(setcdr menu (cons (list nil name) (cdr menu)))
(if name
(define-key menu (vector (intern name)) (cons name command)))))
(setq menu-items (cdr menu-items)))
menu))
(defun popup-menu (menu-desc)
"Pop up the given menu.
A menu is a list of menu items, strings, and submenus.
The first element of a menu must be a string, which is the name of the
menu. This is the string that will be displayed in the parent menu, if
any. For toplevel menus, it is ignored. This string is not displayed
in the menu itself.
A menu item is a vector containing:
- the name of the menu item (a string);
- the `callback' of that item;
- a list of keywords with associated values:
- :active active-p a form specifying whether this item is selectable;
- :suffix suffix a string to be appended to the name as an `argument'
to the command, like `Kill Buffer NAME';
- :keys command-keys a string, suitable for `substitute-command-keys',
to specify the keyboard equivalent of a command
when the callback is a form (this is not necessary
when the callback is a symbol, as the keyboard
equivalent is computed automatically in that case);
- :style style a symbol: nil for a normal menu item, `toggle' for
a toggle button (a single option that can be turned
on or off), or `radio' for a radio button (one of a
group of mutually exclusive options);
- :selected form for `toggle' or `radio' style, a form that specifies
whether the button will be in the selected state.
Alternately, the vector may contain exactly 3 or 4 elements, with the third
element specifying `active-p' and the fourth specifying `suffix'.
If the `callback' of a menu item is a symbol, then it must name a command.
It will be invoked with `call-interactively'. If it is a list, then it is
evaluated with `eval'.
If an element of a menu is a string, then that string will be presented in
the menu as unselectable text.
If an element of a menu is a string consisting solely of hyphens, then that
item will be presented as a solid horizontal line.
If an element of a menu is a list, it is treated as a submenu. The name of
that submenu (the first element in the list) will be used as the name of the
item representing this menu on the parent.
The syntax, more precisely:
form := <something to pass to `eval'>
command := <a symbol or string, to pass to `call-interactively'>
callback := command | form
active-p := <t or nil, whether this thing is selectable>
text := <string, non selectable>
name := <string>
suffix := <string>
command-keys := <string>
object-style := 'nil' | 'toggle' | 'radio'
keyword := ':active' active-p
| ':suffix' suffix
| ':keys' command-keys
| ':style' object-style
| ':selected' form
menu-item := '[' name callback active-p [ suffix ] ']'
| '[' name callback [ keyword ]+ ']'
menu := '(' name [ menu-item | menu | text ]+ ')'"
(let ((menu (make-lucid-menu-keymap (car menu-desc) (cdr menu-desc)))
(pos (mouse-pixel-position))
answer cmd)
(while (and menu
(setq answer (x-popup-menu (list (list (nth 1 pos)
(nthcdr 2 pos))
(car pos))
menu)))
(setq cmd (lookup-key menu (apply 'vector answer)))
(setq menu nil)
(and cmd
(if (keymapp cmd)
(setq menu cmd)
(call-interactively cmd))))))
(defun popup-dialog-box (data)
"Pop up a dialog box.
A dialog box description is a list.
- The first element of the list is a string to display in the dialog box.
- The rest of the elements are descriptions of the dialog box's buttons.
Each one is a vector of three elements:
- The first element is the text of the button.
- The second element is the `callback'.
- The third element is t or nil, whether this button is selectable.
If the `callback' of a button is a